﻿using System;
using System.Collections;
using System.Data;
using System.Web;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using AnyOffice.Components;
using AnyOffice.DAL;
using AnyOffice.Model;
using AnyOffice.WorkFlowRegex;
namespace AnyOffice.general.system.workflow.flow_type
{
    public partial class type_process_setcondition : ModulePage
    { 
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.Page.IsPostBack)
            {
                int num = (Request.QueryString["flow_id"] == null) ? 0 : int.Parse(Request.QueryString["flow_id"].ToString());
                this.ViewState["FlowId"] = num;
                bool flag = Request.QueryString["graph"] != null;
                this.ViewState["IsGraph"] = flag;
                if (flag)
                {
                    this.litButton.Text = "<input type=\"button\" value=\"关闭\" class=\"BigButton\" name=\"back\" onClick=\"window.close();\">";
                }
                else
                {
                    this.litButton.Text = "<input type=\"button\" value=\"返回\" class=\"BigButton\" name=\"back\" onClick=\"history.back();\">";
                }
                int ol = (Request.QueryString["id"] == null) ? 0 : int.Parse(Request.QueryString["id"].ToString());
                this.ViewState["Id"] = ol;
                DataTable table = new FlowProcessDao().SelectById(base.Conn, ol);
                if (table.Rows.Count == 0)
                {
                    return;
                }
                if (table.Rows[0]["PrcsIn"] != DBNull.Value)
                {
                    this.PRCS_IN.Value = table.Rows[0]["PrcsIn"].ToString();
                }
                if (table.Rows[0]["PrcsOut"] != DBNull.Value)
                {
                    this.PRCS_OUT.Value = table.Rows[0]["PrcsOut"].ToString();
                }
                if (table.Rows[0]["PrcsInSet"] != DBNull.Value)
                {
                    this.PRCS_IN_SET.Value = table.Rows[0]["PrcsInSet"].ToString();
                }
                if (table.Rows[0]["PrcsOutSet"] != DBNull.Value)
                {
                    this.PRCS_OUT_SET.Value = table.Rows[0]["PrcsOutSet"].ToString();
                }
                DataTable table2 = new FlowFormTypeDao().SelectByFlowId(base.Conn, num);
                FormRegex regex = new FormRegex();
                if (table2.Rows.Count > 0)
                {
                    regex.HtmlSource = (table2.Rows[0]["FormModel"] != DBNull.Value) ? table2.Rows[0]["FormModel"].ToString() : "";
                }
                ArrayList titleValue = regex.GetTitleValue();
                for (int i = 0; i < titleValue.Count; i++)
                {
                    ListItem item = new ListItem(titleValue[i].ToString());
                    this.ITEM_NAME.Items.Insert(i, item);
                }
            }
            if (this.Page.IsPostBack)
            {
                FlowProcessDao dao3 = new FlowProcessDao();
                FlowProcessData data = new FlowProcessData();
                data.Id = Convert.ToInt32(this.ViewState["Id"].ToString());
                if (this.PRCS_IN.Value.Trim() != string.Empty)
                {
                    data.PrcsIn = this.PRCS_IN.Value;
                }
                if (this.PRCS_OUT.Value.Trim() != string.Empty)
                {
                    data.PrcsOut = this.PRCS_OUT.Value;
                }
                if (this.PRCS_IN_SET.Value.Trim() != string.Empty)
                {
                    data.PrcsInSet = this.PRCS_IN_SET.Value;
                }
                if (this.PRCS_OUT_SET.Value.Trim() != string.Empty)
                {
                    data.PrcsOutSet = this.PRCS_OUT_SET.Value;
                }
                dao3.SetCondition(base.Conn, data);
                base.CloseConn();
                if (Convert.ToBoolean(this.ViewState["IsGraph"].ToString()))
                {
                    if (!this.Page.IsStartupScriptRegistered("SefClose"))
                    {
                        this.Page.RegisterStartupScript("SefClose", "<script>parent.opener.location.reload();\nwindow.close();</script>\n");
                    }
                }
                else
                {
                    Response.Redirect("type_view_list.aspx?flow_id=" + this.ViewState["FlowId"].ToString());
                }
            }
        }
       
    }
}

